package aglieBpm.contants;

import java.text.MessageFormat;

public class SqlTemplate {

	public static final String _mytodolistlimit10 = 
			"	SELECT DISTINCT def.name_ AS 'bpm_name_' ,task.*, ins.biz_key_, def.key_  \r\n"+ 
			"   FROM bpm_task task LEFT JOIN bpm_task_identitylink identitylink on task.id_ =  identitylink.task_id_\r\n" + 
			"   INNER join bpm_definition def on task.def_id_ = def.id_\r\n" + 
			"   INNER join bpm_instance ins on ins.id_ = task.inst_id_\r\n" + 
			"	WHERE task.assignee_id_ IS NOT NULL \r\n" +
			"	ORDER BY priority_ DESC, task.id_ DESC\r\n" + 
			"	LIMIT {0} , {1}" ;
	
	public static final String _bpmTaskOpinion = 
			"	SELECT * FROM bpm_task_opinion \r\n" + 
			"	WHERE \r\n" + 
			"	inst_id_= {0}\r\n" + 
			"	ORDER BY case when approve_time_ is null then 1 else 0 end asc ,create_time_,id_" ;
	
	public static final String _listPermissionCode = 
			"	SELECT\r\n" + 
			"	identitylink.type_ AS type,  identitylink.identity_ AS identity\r\n" + 
			"	FROM\r\n" + 
			"	bpm_task task\r\n" + 
			"	LEFT JOIN bpm_task_identitylink identitylink ON task.id_ = identitylink.task_id_\r\n" + 
			"	WHERE\r\n" + 
			"	task.task_id_ = {0}\r\n" + 
			"	AND identity_ IS NOT NULL " ;
	
	public static final String _receivePhoneTypeOrg =
			"	SELECT DISTINCT user_id , user_name , real_name , phone FROM f_user \r\n" + 
			"   WHERE org_id = {0} AND phone IS NOT NULL " ;
	
	public static final String _receivePhoneTypeUser = 
			"	SELECT DISTINCT user_id , user_name , real_name , phone FROM f_user \r\n" + 
			"   WHERE user_id = {0} AND phone IS NOT NULL " ;
	
	public static final String _receivePhoneTypeProject = 
			"	SELECT DISTINCT u.user_id , u.user_name , u.real_name , u.phone FROM f_user u\r\n" + 
			"	INNER JOIN f_user_role ur ON u.user_id = ur.user_id\r\n" + 
			"	INNER JOIN f_role r ON ur.role_id = r.role_id\r\n" + 
			"	WHERE ur.project_id= {0} AND phone IS NOT NULL AND r.role_code = 'xmfzr'" ;
	
	public static final String _receivePhoneTypeRole = 
			"	SELECT DISTINCT u.user_id , u.user_name , u.real_name , u.phone FROM f_user u \r\n" + 
			"    INNER JOIN f_user_role ur ON u.user_id = ur.user_id \r\n" + 
			"    WHERE ur.role_id = {0} AND phone IS NOT NULL " ;
	
	public static final String _receivePhoneTypeGov = 
			"	SELECT DISTINCT u.user_id , u.user_name , u.real_name , u.phone  FROM f_user u\r\n" + 
			"	INNER JOIN f_organization o ON u.org_id = o.org_id\r\n" + 
			"   WHERE o.org_business_id = {govOrgId} AND phone IS NOT NULL " ;
	
	public static final String _receivePhoneTypeGovRole = 
			"   SELECT DISTINCT u.user_id , u.user_name , u.real_name , u.phone  FROM f_user u \r\n" + 
			"	INNER JOIN f_user_role ur ON u.user_id = ur.user_id\r\n" + 
			"	WHERE u.org_id = {0} AND role_id = {1}" ;
	
	public static final String _receivePhoneTypeProjectRole =
			"	SELECT DISTINCT u.user_id , u.user_name , u.real_name , u.phone  FROM f_user u \r\n" + 
			"   INNER JOIN f_user_role ur ON u.user_id = ur.user_id \r\n" + 
			"   INNER JOIN f_user_project up ON u.user_id = up.user_id \r\n" + 
			"   WHERE ur.role_id = {0} AND up.project_id = {1} AND phone IS NOT NULL " ;
	
	public static final String _receivePhoneTypeCompany =
			"	SELECT DISTINCT u.user_id , u.user_name , u.real_name , u.phone  FROM f_user u\r\n" + 
			"    INNER JOIN f_corp_basic_info c ON u.user_name = c.corp_code\r\n" + 
			"	WHERE c.corp_id = {0} AND u.phone IS NOT NULL" ;
	
	
	public static String sqlFormat(String template , String ...args) {
		if(args.length>0) {
			return MessageFormat.format(template, args) ;
		}
		return template ;
	}
	
	
	
}
